<?php
namespace app\admin\Controller;
class Set extends Common {


	//管理员表
	private $table_admin = "";

	/*
	*	构造函数
	*/
	function __construct(){
		parent::__construct();
	}

	public function index(){
		$web_set_result = db('web_set')->field('name,keyword,copy,telephone,type,logo,qr,banner')->find();

		if(request()->isAjax()){
			$name = input('name');
			$keyword = input('keyword');
			$telephone = input('telephone');
			$copy = input('copy');
			$logo = request()->file('logo');
			$qr = request()->file('qr');
			$banner = request()->file('banner');
			$data = array();
			if(!empty($name)){
				$data['name'] = $name;
			}
			if(!empty($keyword)){
				$data['keyword'] = $keyword;
			}
			if(!empty($telephone)){
				$data['telephone'] = $telephone;
			}
			if(!empty($copy)){
				$data['copy'] = $copy;
			}

			if(!empty($logo)){
				$info = $logo->move(ROOT_PATH . 'public/static/uploads');
				if ($info) {
					$data['logo'] = $info->getSaveName();
				}
			}

			if(!empty($qr)){
				$info = $qr->move(ROOT_PATH . 'public/static/uploads');
				if ($info) {
//					$this->success('aa');
					$data['qr'] = $info->getSaveName();
				}
			}

			if(!empty($banner)){
				$info = $banner->move(ROOT_PATH . 'public/static/uploads');
				if ($info) {
					$data['banner'] = $info->getSaveName();
				}
			}

			if(!empty($type)){
				$data['type'] = $type;
			}

			$bool = db('web_set')->where(array('id'=>'1'))->update($data);

			if(!$bool)$this->error('修改失败');
			$this->success('修改成功!');
		}
		$this->assign('web_set_result', $web_set_result);
		return 	$this->fetch();
	}

	//关于我们
	public function about(){
		$web_set_result = db('web_set')->field('about')->find();

		if(request()->isAjax()){
			$about = input('about');
			$bool = db('web_set')->where(array('id'=>'1'))->update(array('about'=>$about));

			if(!$bool)$this->error('修改失败');
			$this->success('修改成功!');
		}

		$this->assign('web_set_result', $web_set_result);
		return 	$this->fetch();
	}


}